/*
 * @Author: wangqizhang
 * @Date: 2024-05-11 09:28:52
 * @LastEditors: wangqizhang
 * @LastEditTime: 2024-05-12 15:21:41
 * @FilePath: /suixinji-react/src/page/group/index.tsx
 * @Description:
 *
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */
import { useEffect, useState } from 'react';
import XTable from '../../components/XTable';
import { Table, message, Tag, Space } from 'antd';
import { getGroupList, getGroupListByPage } from '../../api';
import { render } from 'react-dom';
import { positionElement } from 'echarts/types/src/util/layout.js';
import { AlignCenterOutlined } from '@ant-design/icons';

const columns: any = [
  {
    title: '分组名称',
    dataIndex: 'group_name',
    key: 'group_name',
  },
  {
    title: '分组标签',
    dataIndex: 'group_tag',
    key: 'group_tag',
    render: (text: any) => <Tag color="processing">{text}</Tag>,
    align: 'center',
  },
  {
    title: '创建时间',
    dataIndex: 'createdAt',
    key: 'createdAt',
    render: (text: any) => <span>{text.replace('T', ' ')}</span>,
    align: 'center',
  },
  {
    title: '更新时间',
    dataIndex: 'updatedAt',
    key: 'updatedAt',
    render: (text: any) => <span>{text.replace('T', ' ')}</span>,
    align: 'center',
  },
  {
    title: '操作',
    dataIndex: 'action',
    key: 'action',
    render: (text: any, record: any) => {
      return (
        <Space>
          <a style={{ color: '#f40' }}>删除</a>
        </Space>
      );
    },
    align: 'center',
  },
];
const GroupConfig = () => {
  const [messageApi, contextHolder] = message.useMessage();
  const [data, setData] = useState<any[]>([]);
  const [searQuery, setSearQuery] = useState<any>({
    group_name: undefined,
    id: undefined,
  });
  const [pageQuery, setPageQuery] = useState<any>({
    offset: 1,
    limit: 10,
  });
  const getData = async () => {
    const res = await getGroupList();
    if (res.code === '0000') {
      setData(res.data);
    } else {
      messageApi.error(res.msg);
    }
  };
  useEffect(() => {
    getData();
  }, []);
  return <Table columns={columns} dataSource={data} rowKey="id"></Table>;
};
export default GroupConfig;
